package com.zmzncs.lmtc.module.order.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmzncs.lmtc.common.pojo.PageVO;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.order.pojo.order_refund.OrderRefundApplyForm;
import com.zmzncs.lmtc.module.order.pojo.order_refund.OrderRefundDTO;
import com.zmzncs.lmtc.module.order.pojo.order_refund.OrderRefundSelectVO;
import com.zmzncs.lmtc.module.order.service.OrderRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * <p>
 * 订单-退款 前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2020-10-21
 */
@Api(tags = "退款")
@RestController
@RequestMapping("/order/order-refund")
@Validated
@Slf4j
public class OrderRefundController {

    @Autowired
    OrderRefundService orderRefundService;

    @ApiOperation(value = "申请退款")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping(value = "applyRefund")
    public Rest<Map<String,Object>> applyRefund(@RequestBody @Valid OrderRefundApplyForm form) {
        Map<String, Object> map = orderRefundService.applyRefund(form);
        return RestUtil.success(map);
    }

    @ApiOperation(value = "查询退款信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name="pageNum", value="页码", required = true),
            @ApiImplicitParam(paramType="query", name="pageSize", value="页长", required = true),
    })
    @GetMapping(value = "getOrderRefundPage")
    public Rest<PageVO<OrderRefundSelectVO>> getOrderRefundPage(@NotNull Integer pageNum, @NotNull Integer pageSize){

        IPage<OrderRefundDTO> orderRefundPage = orderRefundService.getOrderRefundPage(new Page<>(pageNum, pageSize));
        PageVO<OrderRefundSelectVO> page = JsonUtil.pageTransform(orderRefundPage, OrderRefundSelectVO.class);
        return RestUtil.success(page);
    }

}